package com.nio;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @author zhuangqi
 * @date 2017/9/12.
 */
public class NioBufferReadDemo {

    public static void main(String[] args) {
        try {
            FileInputStream is = new FileInputStream("E:\\test.txt");
            FileChannel channel = is.getChannel();
            ByteBuffer buffer = ByteBuffer.allocate(1024);
            channel.read(buffer);
            System.out.println(new String(buffer.array()));
            buffer.clear();
            channel.close();
            is.close();
        } catch (java.io.IOException e) {
            e.printStackTrace();
        }
    }
}
